package org.shj;

import com.hankcs.hanlp.HanLP;
import com.hankcs.hanlp.corpus.io.IIOAdapter;
import com.hankcs.hanlp.utility.Predefine;
import org.shj.util.PropertyUtil;

import java.io.*;
import java.util.Properties;

/**
 * @author Shen Huang Jian
 * @date 2020-08-25 17:47
 */
public class FullFileIOAdapter implements IIOAdapter{
    private static String root;
    private static String absoluteRootPath;
    static {
        root = PropertyUtil.getRootDataFolder();
        File file = new File(root);
        //主要为了消除windows 中路径 / 和 linux 中的路径 \ 的问题
        absoluteRootPath = file.getAbsolutePath();
    }
    @Override
    public InputStream open(String path) throws FileNotFoundException
    {
        if(path.startsWith(absoluteRootPath) || path.startsWith(root)){
            return new FileInputStream(path);
        }
        return new FileInputStream(root + path);
    }

    @Override
    public OutputStream create(String path) throws FileNotFoundException
    {
        if(path.startsWith(root)){
            return new FileOutputStream(path);
        }
        return new FileOutputStream(root + path);
    }
}
